package com.frame.study2rxjava;

import android.os.Bundle;
import android.support.annotation.MainThread;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.TextView;

import com.commonlibrary.httpframe.HttpResultObserver;
import com.commonlibrary.httpframe.ListenerHttpResult;
import com.commonlibrary.httpframe.RetrofitManager;
import com.frame.R;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;

/**
 * retrofit + rxjava 封装框架使用
 */
public class RxFrameActivity extends AppCompatActivity {

    private TextView tvContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simplest);
        tvContent = findViewById(R.id.tv_content);


        HttpResultObserver mObserver = new HttpResultObserver(this, new ListenerHttpResult() {
            @Override
            public void onSuccess(String result) {
                tvContent.setText(result);
            }

            @Override
            public void onFail(String errorMsg) {
                tvContent.setText(errorMsg);
            }
        });
        Observable<ResponseBody> observable = RetrofitManager.getInstance().getApis().
                getRepos("octocat");


        RetrofitManager.getInstance().subscribe(observable, mObserver);

    }
}
